home *** CD-ROM | disk | FTP | other *** search
- *-----------------------------------------------------------------------
- *-- Program...: WPMrgDem.prg
- *-- Programmer: Kenneth Chan (HazMatZak) (CIS: 72662,1305)
- *-- Notes.....: Demo WP merge -- generate WP merge files directly
- *-- from dBASE
- *-- Date......: 12/02/1993
- *-- More Expl.: There are two drivers, WPMERGE.PR2 and WPMERGEB.PR2,
- *-- the only difference being that WPMERGEB has more
- *-- aggressive bold support. Both "B" and "U" STYLEs
- *-- for ?/?? work -- the resulting WP text will be bolded
- *-- and/or underlined.
- *--
- *-- The problem is that dBASE does not turn off bolding
- *-- unless it knows the next expression is not bold. If
- *-- the last (or only) expression in a field is bold, the
- *-- ending bold code ([bold] for the Reveal Codes-literate)
- *-- does not appear until the beginning of the next field.
- *-- This can cause rampant bolding in the resulting merged
- *-- document.
- *--
- *-- WPMERGEB "fixes" this by including [Bold][bold] codes
- *-- at the end of every field. When the generated file is
- *-- converted by WordPerfect, it causes the bold to end at
- *-- the end of the field, and eliminates the [bold] at the
- *-- beginning of the next field. Unfortunately, if the
- *-- last expression does not have a bold, there will be a
- *-- [Bold][bold] at the end of the field. This has no ill
- *-- effect, other than to uglify your WordPerfect document.
- *-- You can use a global search and replace to remove them,
- *-- but....
- *--
- *-- If you're not generating a merge file with bold in it
- *-- (and it's not clear why you'd want to do it in the
- *-- first place), use the WPMERGE.PR2 driver instead; it
- *-- does not have the extra bold codes.
- *-----------------------------------------------------------------------
-
- *-- Fake some data in a .DBF with an array
- declare aDbf[ 3, 5 ]
- aDbf[ 1, 1 ] = "Jane Doe" && "record" 1
- aDbf[ 1, 2 ] = "1234 Main St"
- aDbf[ 1, 3 ] = "Anywhere"
- aDbf[ 1, 4 ] = "US"
- aDbf[ 1, 5 ] = "12345"
- aDbf[ 2, 1 ] = "Ods Bodkins" && "record" 2
- aDbf[ 2, 2 ] = "987 W 654th St"
- aDbf[ 2, 3 ] = "New York"
- aDbf[ 2, 4 ] = "NY"
- aDbf[ 2, 5 ] = "11011"
- aDbf[ 3, 1 ] = "Al Bendova" && "record" 3
- aDbf[ 3, 2 ] = "3300 Alameda"
- aDbf[ 3, 3 ] = "Burbank"
- aDbf[ 3, 4 ] = "CA"
- aDbf[ 3, 5 ] = "91506"
-
- *-- Temporary changes to system memvars
- private _pdriver, _padvance
- *-- Use the WPMERGEB.PR2 printer driver because there's bolded text
- _pdriver = "WPMERGEB.PR2"
- *-- and advance by form feed for EJECT PAGE
- _padvance = "FORMFEED"
-
- *-- Redirect printing to a file
- cFile = "MAIL.LST"
- set safety off
- set printer to file ( cFile )
- set safety on
- set print on
- set console off
-
- nRec = 1
- do while nRec <= 3
-
- *-- First field always ?? AT 0
- ?? aDbf[ nRec, 1 ] at 0 && Name
-
- *-- Subsequent fields print with ?
- ? aDbf[ nRec, 2 ] && Address
-
- *-- Bold and underline styles work
- *-- (at least in WP/DOS 5.1) && City, State, Zip
- ? aDbf[ nRec, 3 ], aDbf[ nRec, 4 ], aDbf[ nRec, 5 ] style "B"
-
- *-- End record with EJECT PAGE or ?? CHR( 12 ) but not EJECT
- eject page
-
- nRec = nRec + 1
- enddo
-
- set console on
- set print off
- *-- Close file
- set printer to
- *-- Remove EOF marker
- do RemoveEOF with cFile
- *-- Merge file with WPMRGDEM.WPD in WordPerfect
-
- RETURN
-
-
-
- PROCEDURE RemoveEOF
- *-----------------------------------------------------------------------
- *-- Programmer..: Kenneth Chan [Zak] (CIS: 72662,1305)
- *-- Date........: 09/23/1993
- *-- Notes.......: Remove EOF marker from files
- *-- Written for.: dBASE IV, 1.5
- *-- Rev. History: 09/23/1993 1.0
- *-- Calls.......: <none>
- *-- Called by...: <any>
- *-- Usage.......: RemoveEOF with <cFile>
- *-- Example.....: do RemoveEOF with "PRINTOUT.TXT"
- *-- Returns.....: <na>
- *-- Parameters..: cFile = name of file to truncate
- *-----------------------------------------------------------------------
-
- parameter cFile
- *-- Make sure file exists
- if file( cFile )
- hFile = fopen( cFile, "RW" )
- *-- If successful file open
- if hFile > 0
- *-- Goto last byte
- nPtr = fseek( hFile, -1, 2 )
- *-- If it's an EOF
- if fread( hFile, 1 ) = chr( 26 )
- *-- Reposition pointer
- nPtr = fseek( hFile, -1, 2 )
- *-- Truncate file
- nPtr = fwrite( hFIle, "" )
- endif
- *-- Close file
- nPtr = fclose( hFile )
- endif
- endif
-
- RETURN
- *-- EoP: RemoveEoF